﻿using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using MyIDP.Models;
using System.Security.Claims;

namespace MyIDP.Permission
{
    public class MyUserManager : UserManager<ApplicationUser>
    {
        public MyUserManager(IUserStore<ApplicationUser> store, IOptions<IdentityOptions> optionsAccessor, IPasswordHasher<ApplicationUser> passwordHasher,
          IEnumerable<IUserValidator<ApplicationUser>> userValidators, IEnumerable<IPasswordValidator<ApplicationUser>> passwordValidators, ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, IServiceProvider services, ILogger<UserManager<ApplicationUser>> logger)
           : base(store, optionsAccessor, new MyPasswordHasher(), userValidators, passwordValidators, keyNormalizer, errors, services, logger)
        {
            optionsAccessor.Value.Password.RequireDigit = false;
            optionsAccessor.Value.Password.RequiredLength = 4;
            optionsAccessor.Value.Password.RequireLowercase = false;
            optionsAccessor.Value.Password.RequireUppercase = false;
            optionsAccessor.Value.Password.RequireNonAlphanumeric = false;
        }


        //public async Task<bool> ValidateCredentialsAsync(string username, string userpwd)
        //{
        //    if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(userpwd))
        //    {
        //        return false;
        //    }
        //    var user = await FindByNameAsync(username);
        //    if (user == null)
        //    {
        //        return false;
        //    }
        //    //检验用户密码（虽然我也不知道他的密码是采用什么加密方式得到的，但是我也不需要知道） 
        //    var passwordPass = await CheckPasswordAsync(user, userpwd);
        //    return passwordPass;
        //}
    }
}
